
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Get extends JPanel implements ActionListener {
    private JButton backBtn;
    private JButton sure;
    private Atmtest frame;
    private JTextField quqian;
    private double yuE;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

    }

    public Get(Atmtest frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        quqian = new JTextField();
        quqian.setBounds(180, 500, 200, 30);
        this.add(quqian);

        sure = new JButton(Util.getIcon("/img/buttonSure.jpg"));
        sure.setBounds(900, 400, 100, 50);
        this.add(sure);
        sure.addActionListener(this);

        backBtn = new JButton(Util.getIcon("/img/buttonOff.jpg"));
        backBtn.setBounds(900, 330, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

    }

    public void setmoney() {
        yuE = frame.getUsers().get(frame.getID()).getBalance();
        System.out.println(yuE);
        this.yuE = yuE;
    }

    public void getmoney() {
            System.out.println(quqian.getText());
            yuE -= Integer.parseInt(quqian.getText());
            frame.getUsers().get(frame.getID()).setBalance(yuE);
        }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (backBtn == e.getSource()) {
            frame.switchPanel("menu");
        }
        if (sure == e.getSource()) {
            frame.getGet().getmoney();
            quqian.setText("");
        }
    }
}